#include "InviteResultNotify.h"

json InviteResultNotify::serialize() const {
    try{
        json j;
        j["type"]=type;
        j["sender_id"]=sender_id;
        j["receiver_id"]=receiver_id;
        j["chat_room_id"]=chat_room_id;
        j["content"]=content;
        j["time"]=time;
        j["accept"]=accept;
        return j;
    }catch(exception& e){
        syslog(LOG_ERR, "InviteResultNotify serialize error:%s", e.what());
        #ifdef DEBUG
        PRINT_ERRNO_AND_STRERROR(errno, "InviteResultNotify serialize error:%s", e.what());
        #endif
        throw e;
    }
}

void InviteResultNotify::unserialize(const json& j) {
    try{
        this->type=j["type"].get<NotifyType>();
        this->sender_id=j["sender_id"].get<int>();
        this->receiver_id=j["receiver_id"].get<int>();
        this->chat_room_id=j["chat_room_id"].get<string>();
        this->content=j["content"].get<string>();
        this->time=j["time"].get<string>();
        this->accept=j["accept"].get<bool>();
    }catch(exception& e){
        syslog(LOG_ERR, "InviteResultNotify unserialize error:%s", e.what());
        #ifdef DEBUG
        PRINT_ERRNO_AND_STRERROR(errno, "InviteResultNotify unserialize error:%s", e.what());
        #endif  
        throw e;
    }
}

NotifyType InviteResultNotify::get_notify_type() const {
    return INVITE_RESULT_NOTIFY;
}

InviteResultNotify::InviteResultNotify(const int& sender_id, const int& receiver_id,const string& chat_room_id, const string& content, const string& time, bool accept)
   {
    this->sender_id = sender_id;
    this->receiver_id = receiver_id;
    this->type = INVITE_RESULT_NOTIFY;
    this->chat_room_id = chat_room_id;
    this->content = content;
    this->time = time;
    this->accept = accept;
}

InviteResultNotify::InviteResultNotify(json invite_result_notify_json) {
    unserialize(invite_result_notify_json);
}
